
var http = require('http');
var https = require('https');
var fs = require('fs');
var logic=require('./logic');
// var ws = require("nodejs-websocket");
var CONST=require("./const");
var Log=require("./log");

// 启动http服务
try{
    http.createServer(function (request, response) {
       if(url.parse(request.url).pathname!='/favicon.ico'){
         var arg=url.parse(request.url.replace(/amp;/g ,""),true).query;
         try{
              logic.LogicDel(arg, response,function(data,response){
                if(data){
                  response.end(JSON.stringify(data));
                 }
              });
            }catch(exception) {
              Log.error("http/logic",exception);
            }
       }
    }).listen(CONST.httpServerProt());

    Log.Log('HttpServer running at http://127.0.0.1:'+CONST.httpServerProt());

}catch(e){
  Log.error("http",e)
}

//SSL证书
var options = {
  key: fs.readFileSync('./uk5/al.key'),
  cert: fs.readFileSync('./uk5/al.pem')
};

//启动https服务
try{
    https.createServer(options,function (request, response) {
       if(url.parse(request.url).pathname!='/favicon.ico'){
         var arg=url.parse(request.url.replace(/amp;/g ,""),true).query;
         try{
            logic.LogicDel(arg, response,function(data,response){
                if(data){
                  response.end(JSON.stringify(data));
                 }
              });
            }catch(exception) {
              Log.error("https/logic",exception);
            }
       }
    }).listen(CONST.httpsServerProt());
  Log.Log('HttpServer running at http://127.0.0.1:'+CONST.httpsServerProt());
}catch(e){
  Log.error("https",e)
}
